﻿ using System.Collections.Generic;
using HuaCheng.Model;
using System;

namespace HuaCheng.Controller
{
    public class DataControl
    {
        /// <summary>
        /// 读取List中的数据将其转换成默认单位对应的数据
        /// </summary>
        /// <param name="dicUnit"></param>
        /// <returns></returns>
        public static List<StepInfo> DataConvertToDefault(List<StepInfo> stepInfoList)
        {
            //读取当前定制的单位
            Dictionary<string, string> dicUnit = IniControl.ReadCustom("unit custom");
            //将当前表格中的数据转换成默认单位对应的数据
            stepInfoList.ForEach(o =>
            {
                if (o.StepName != "循环" && o.StepName != "搁置" && o.StepName != "斜坡工况" && o.StepName != "脉冲工况" && o.StepName != "模拟工况" && o.StepName != "暂停" && o.StepName != "结束")
                {
                    //记录条件中时间单位的转换
                    if (dicUnit["Time"] != "sec")
                    {
                        if (o.ChildList != null)
                        {
                            for (int i = 0; i < o.ChildList.Count; i++)
                            {
                                if (o.ChildList[i].ChildStepName == "记录条件")
                                {
                                    if (o.ChildList[i].RecordCond == "时间段")
                                    {
                                        o.ChildList[i].CondLower = (o.ChildList[i].CondLower == null) ? null : Convert.ToString(Convert.ToSingle(o.ChildList[i].CondLower) / 1000);
                                        o.ChildList[i].CondUpper = (o.ChildList[i].CondUpper == null) ? null : Convert.ToString(Convert.ToSingle(o.ChildList[i].CondUpper) / 1000);
                                    }
                                    o.ChildList[i].TimeInterval = (o.ChildList[i].TimeInterval == null) ? null : Convert.ToString(Convert.ToSingle(o.ChildList[i].TimeInterval) / 1000);
                                }
                                else if (o.ChildList[i].ChildStepName == "如果")
                                {
                                    if (o.ChildList[i].JumpCond.Contains("工步时间"))
                                    {
                                        o.ChildList[i].JumpValue = (o.ChildList[i].JumpValue == null) ? null : Convert.ToString(Convert.ToSingle(o.ChildList[i].JumpValue) / 1000);
                                    }
                                }
                            }
                        }
                        if (o.ProtCondition != null)
                        {
                            o.ProtCondition.TimeSpan = (o.ProtCondition.TimeSpan == null) ? "0" : Convert.ToString(Convert.ToSingle(o.ProtCondition.TimeSpan) / 1000);
                            o.ProtCondition.StepDelay = (o.ProtCondition.StepDelay == null) ? "0" : Convert.ToString(Convert.ToSingle(o.ProtCondition.StepDelay) / 1000);
                            o.ProtCondition.ContinueDelay = (o.ProtCondition.ContinueDelay == null) ? "0" : Convert.ToString(Convert.ToSingle(o.ProtCondition.ContinueDelay) / 1000);
                            o.ProtCondition.DetectionTime = (o.ProtCondition.DetectionTime == null) ? "0" : Convert.ToString(Convert.ToSingle(o.ProtCondition.DetectionTime) / 1000);
                        }
                    }
                    if (dicUnit["Voltage"] != "V")
                    {
                        o.Voltage = (o.Voltage == null) ? null : Convert.ToString(Convert.ToSingle(o.Voltage) / 1000);
                        o.DeltaVolt = (o.DeltaVolt == null) ? null : Convert.ToString(Convert.ToSingle(o.DeltaVolt) / 1000);
                        o.MaxVi = (o.MaxVi == null) ? null : Convert.ToString(Convert.ToSingle(o.MaxVi) / 1000);
                        o.MinVi = (o.MinVi == null) ? null : Convert.ToString(Convert.ToSingle(o.MinVi) / 1000);
                        o.SingleVolt = (o.SingleVolt == null) ? null : Convert.ToString(Convert.ToSingle(o.SingleVolt) / 1000);
                        if (o.StepName == "恒压斜坡充电" || o.StepName == "恒压斜坡放电")
                        {
                            o.BeginValue = (o.BeginValue == null) ? null : Convert.ToString(Convert.ToSingle(o.BeginValue) / 1000);
                            o.EndValue = (o.EndValue == null) ? null : Convert.ToString(Convert.ToSingle(o.EndValue) / 1000);
                        }
                        if (o.ChildList != null)
                        {
                            for (int i = 0; i < o.ChildList.Count; i++)
                            {
                                if (o.ChildList[i].ChildStepName == "如果")
                                {
                                    if (o.ChildList[i].JumpCond.Contains("电压"))
                                    {
                                        o.ChildList[i].JumpValue = (o.ChildList[i].JumpValue == null) ? null : Convert.ToString(Convert.ToSingle(o.ChildList[i].JumpValue) / 1000);
                                    }
                                }
                                else if (o.ChildList[i].ChildStepName == "记录条件")
                                {
                                    if (o.ChildList[i].RecordCond == "电压段")
                                    {
                                        o.ChildList[i].CondLower = (o.ChildList[i].CondLower == null) ? null : Convert.ToString(Convert.ToSingle(o.ChildList[i].CondLower) / 1000);
                                        o.ChildList[i].CondUpper = (o.ChildList[i].CondUpper == null) ? null : Convert.ToString(Convert.ToSingle(o.ChildList[i].CondUpper) / 1000);
                                    }
                                    o.ChildList[i].VolInterval = (o.ChildList[i].VolInterval == null) ? null : Convert.ToString(Convert.ToSingle(o.ChildList[i].VolInterval) / 1000);
                                }
                            }
                        }
                        if (o.ProtCondition != null)
                        {
                            o.ProtCondition.VoltageSpan = (o.ProtCondition.VoltageSpan == null) ? "0" : Convert.ToString(Convert.ToSingle(o.ProtCondition.VoltageSpan) / 1000);
                            o.ProtCondition.VoltageMin = (o.ProtCondition.VoltageMin == null) ? "0" : Convert.ToString(Convert.ToSingle(o.ProtCondition.VoltageMin) / 1000);
                            o.ProtCondition.VoltageMax = (o.ProtCondition.VoltageMax == null) ? "0" : Convert.ToString(Convert.ToSingle(o.ProtCondition.VoltageMax) / 1000);
                            o.ProtCondition.Platform1 = (o.ProtCondition.Platform1 == null) ? "0" : Convert.ToString(Convert.ToSingle(o.ProtCondition.Platform1) / 1000);
                            o.ProtCondition.Platform2 = (o.ProtCondition.Platform2 == null) ? "0" : Convert.ToString(Convert.ToSingle(o.ProtCondition.Platform2) / 1000);
                            o.ProtCondition.Platform3 = (o.ProtCondition.Platform3 == null) ? "0" : Convert.ToString(Convert.ToSingle(o.ProtCondition.Platform3) / 1000);
                            o.ProtCondition.VoltageValue = (o.ProtCondition.VoltageValue == null) ? "0" : Convert.ToString(Convert.ToSingle(o.ProtCondition.VoltageValue) / 1000);
                        }
                    }
                    if (dicUnit["Current"] != "A")
                    {
                        o.Current = (o.Current == null) ? null : Convert.ToString(Convert.ToSingle(o.Current) / 1000);
                        o.CutoffCurr = (o.CutoffCurr == null) ? null : Convert.ToString(Convert.ToSingle(o.CutoffCurr) / 1000);
                        o.Amplitude1 = (o.Amplitude1 == null) ? null : Convert.ToString(Convert.ToSingle(o.Amplitude1) / 1000);
                        o.Amplitude2 = (o.Amplitude2 == null) ? null : Convert.ToString(Convert.ToSingle(o.Amplitude2) / 1000);
                        if (o.StepName == "恒流斜坡充电" || o.StepName == "恒流斜坡放电")
                        {
                            o.BeginValue = (o.BeginValue == null) ? null : Convert.ToString(Convert.ToSingle(o.BeginValue) / 1000);
                            o.EndValue = (o.EndValue == null) ? null : Convert.ToString(Convert.ToSingle(o.EndValue) / 1000);
                        }
                        if (o.ChildList != null)
                        {
                            for (int i = 0; i < o.ChildList.Count; i++)
                            {
                                if (o.ChildList[i].ChildStepName == "如果")
                                {
                                    if (o.ChildList[i].JumpCond.Contains("电流"))
                                    {
                                        o.ChildList[i].JumpValue = (o.ChildList[i].JumpValue == null) ? null : Convert.ToString(Convert.ToSingle(o.ChildList[i].JumpValue) / 1000);
                                    }
                                }
                                else if (o.ChildList[i].ChildStepName == "记录条件")
                                {
                                    if (o.ChildList[i].RecordCond == "电流段")
                                    {
                                        o.ChildList[i].CondLower = (o.ChildList[i].CondLower == null) ? null : Convert.ToString(Convert.ToSingle(o.ChildList[i].CondLower) / 1000);
                                        o.ChildList[i].CondUpper = (o.ChildList[i].CondUpper == null) ? null : Convert.ToString(Convert.ToSingle(o.ChildList[i].CondUpper) / 1000);
                                    }
                                    o.ChildList[i].CurrInterval = (o.ChildList[i].CurrInterval == null) ? null : Convert.ToString(Convert.ToSingle(o.ChildList[i].CurrInterval) / 1000);
                                }
                            }
                        }
                        if (o.ProtCondition != null)
                        {
                            o.ProtCondition.CurrentSpan = (o.ProtCondition.CurrentSpan == null) ? null : Convert.ToString(Convert.ToSingle(o.ProtCondition.CurrentSpan) / 1000);
                            o.ProtCondition.CurrentMin = (o.ProtCondition.CurrentMin == null) ? null : Convert.ToString(Convert.ToSingle(o.ProtCondition.CurrentMin) / 1000);
                            o.ProtCondition.CurrentMax = (o.ProtCondition.CurrentMax == null) ? null : Convert.ToString(Convert.ToSingle(o.ProtCondition.CurrentMax) / 1000);
                            o.ProtCondition.CustomerCurrMin = (o.ProtCondition.CustomerCurrMin == null) ? null : Convert.ToString(Convert.ToSingle(o.ProtCondition.CustomerCurrMin) / 1000);
                            o.ProtCondition.CustomerCurrMax = (o.ProtCondition.CustomerCurrMax == null) ? null : Convert.ToString(Convert.ToSingle(o.ProtCondition.CustomerCurrMax) / 1000);
                        }
                    }
                    if (dicUnit["Cap"] != "Ah")
                    {
                        o.Cap = (o.Cap == null) ? null : Convert.ToString(Convert.ToSingle(o.Cap) / 1000);
                        if (o.ChildList != null)
                        {
                            for (int i = 0; i < o.ChildList.Count; i++)
                            {
                                if (o.ChildList[i].ChildStepName == "如果")
                                {
                                    if (o.ChildList[i].JumpCond.Contains("容量"))
                                    {
                                        o.ChildList[i].JumpValue = (o.ChildList[i].JumpValue == null) ? null : Convert.ToString(Convert.ToSingle(o.ChildList[i].JumpValue) / 1000);
                                    }
                                }
                            }
                        }
                    }
                    if (dicUnit["Energy"] != "Wh")
                    {
                        o.Energy = (o.Energy == null) ? null : Convert.ToString(Convert.ToSingle(o.Energy) / 1000);
                        if (o.ChildList != null)
                        {
                            for (int i = 0; i < o.ChildList.Count; i++)
                            {
                                if (o.ChildList[i].ChildStepName == "如果")
                                {
                                    if (o.ChildList[i].JumpCond.Contains("能量"))
                                    {
                                        o.ChildList[i].JumpValue = (o.ChildList[i].JumpValue == null) ? null : Convert.ToString(Convert.ToSingle(o.ChildList[i].JumpValue) / 1000);
                                    }
                                }
                            }
                        }
                    }
                    if (dicUnit["Power"] != "W")
                    {
                        o.Power = (o.Power == null) ? null : Convert.ToString(Convert.ToSingle(o.Power) / 1000);
                        if (o.ChildList != null)
                        {
                            for (int i = 0; i < o.ChildList.Count; i++)
                            {
                                if (o.ChildList[i].ChildStepName == "如果")
                                {
                                    if (o.ChildList[i].JumpCond.Contains("功率"))
                                    {
                                        o.ChildList[i].JumpValue = (o.ChildList[i].JumpValue == null) ? null : Convert.ToString(Convert.ToSingle(o.ChildList[i].JumpValue) / 1000);
                                    }
                                }
                            }
                        }
                    }
                    if (dicUnit["Res"] != "Ω")
                    {
                        o.LoadResistor = (o.LoadResistor == null) ? null : Convert.ToString(Convert.ToSingle(o.LoadResistor) / 1000);
                    }
                    if (dicUnit["Temp"] != "℃")
                    {
                        o.MaxTi = (o.MaxTi == null) ? null : Convert.ToString(Convert.ToSingle(o.MaxTi) / 33.8);
                        o.MinTi = (o.MinTi == null) ? null : Convert.ToString(Convert.ToSingle(o.MinTi) / 33.8);
                        if(o.ProtCondition != null)
                        {
                            o.ProtCondition.TemperatureMax = (o.ProtCondition.TemperatureMax == null) ? "0" : Convert.ToString(Convert.ToSingle(o.ProtCondition.TemperatureMax) / 33.8);
                        }
                    }
                }
            });
            return stepInfoList;
        }
        /// <summary>
        /// 读取List中的数据将其转换成当前单位定制的单位对应的数据
        /// </summary>
        /// <param name="dicUnit"></param>
        /// <param name="stepInfoList"></param>
        /// <returns></returns>
        public static List<StepInfo> DataConvertToCurrent(List<StepInfo> stepInfoList)
        {
            //读取当前定制的单位
            Dictionary<string, string> dicUnit = IniControl.ReadCustom("unit custom");
            stepInfoList.ForEach(o =>
            {
                if (o.StepName != "循环" && o.StepName != "搁置" && o.StepName != "斜坡工况" && o.StepName != "脉冲工况" && o.StepName != "模拟工况" && o.StepName != "暂停" && o.StepName != "结束")
                {
                    if (dicUnit["Time"] != "sec")
                    {
                        if (o.ChildList != null)
                        {
                            for (int i = 0; i < o.ChildList.Count; i++)
                            {
                                if (o.ChildList[i].ChildStepName == "记录条件")
                                {
                                    if (o.ChildList[i].RecordCond == "时间段")
                                    {
                                        o.ChildList[i].CondLower = (o.ChildList[i].CondLower == null) ? null : Convert.ToString(Convert.ToSingle(o.ChildList[i].CondLower) * 1000);
                                        o.ChildList[i].CondUpper = (o.ChildList[i].CondUpper == null) ? null : Convert.ToString(Convert.ToSingle(o.ChildList[i].CondUpper) * 1000);
                                    }
                                    o.ChildList[i].TimeInterval = (o.ChildList[i].TimeInterval == null) ? null : Convert.ToString(Convert.ToSingle(o.ChildList[i].TimeInterval) * 1000);
                                }
                                else if (o.ChildList[i].ChildStepName == "如果")
                                {
                                    if (o.ChildList[i].JumpCond.Contains("工步时间"))
                                    {
                                        o.ChildList[i].JumpValue = (o.ChildList[i].JumpValue == null) ? null : Convert.ToString(Convert.ToSingle(o.ChildList[i].JumpValue) * 1000);
                                    }
                                }
                            }
                        }
                        if (o.ProtCondition != null)
                        {
                            o.ProtCondition.TimeSpan = (o.ProtCondition.TimeSpan == null) ? "0" : Convert.ToString(Convert.ToSingle(o.ProtCondition.TimeSpan) * 1000);
                            o.ProtCondition.StepDelay = (o.ProtCondition.StepDelay == null) ? "0" : Convert.ToString(Convert.ToSingle(o.ProtCondition.StepDelay) * 1000);
                            o.ProtCondition.ContinueDelay = (o.ProtCondition.ContinueDelay == null) ? "0" : Convert.ToString(Convert.ToSingle(o.ProtCondition.ContinueDelay) * 1000);
                            o.ProtCondition.DetectionTime = (o.ProtCondition.DetectionTime == null) ? "0" : Convert.ToString(Convert.ToSingle(o.ProtCondition.DetectionTime) * 1000);
                        }
                    }
                    if (dicUnit["Voltage"] != "V")
                    {
                        o.Voltage = (o.Voltage == null) ? null : Convert.ToString(Convert.ToSingle(o.Voltage) * 1000);
                        o.DeltaVolt = (o.DeltaVolt == null) ? null : Convert.ToString(Convert.ToSingle(o.DeltaVolt) * 1000);
                        o.MaxVi = (o.MaxVi == null) ? null : Convert.ToString(Convert.ToSingle(o.MaxVi) * 1000);
                        o.MinVi = (o.MinVi == null) ? null : Convert.ToString(Convert.ToSingle(o.MinVi) * 1000);
                        o.SingleVolt = (o.SingleVolt == null) ? null : Convert.ToString(Convert.ToSingle(o.SingleVolt) * 1000);
                        if (o.StepName == "恒压斜坡充电" || o.StepName == "恒压斜坡放电")
                        {
                            o.BeginValue = (o.BeginValue == null) ? null : Convert.ToString(Convert.ToSingle(o.BeginValue) * 1000);
                            o.EndValue = (o.EndValue == null) ? null : Convert.ToString(Convert.ToSingle(o.EndValue) * 1000);
                        }
                        if (o.ChildList != null)
                        {
                            for (int i = 0; i < o.ChildList.Count; i++)
                            {
                                if (o.ChildList[i].ChildStepName == "如果")
                                {
                                    if (o.ChildList[i].JumpCond.Contains("电压"))
                                    {
                                        o.ChildList[i].JumpValue = (o.ChildList[i].JumpValue == null) ? null : Convert.ToString(Convert.ToSingle(o.ChildList[i].JumpValue) * 1000);
                                    }
                                }
                                else if (o.ChildList[i].ChildStepName == "记录条件")
                                {
                                    if (o.ChildList[i].RecordCond == "电压段")
                                    {
                                        o.ChildList[i].CondLower = (o.ChildList[i].CondLower == null) ? null : Convert.ToString(Convert.ToSingle(o.ChildList[i].CondLower) * 1000);
                                        o.ChildList[i].CondUpper = (o.ChildList[i].CondUpper == null) ? null : Convert.ToString(Convert.ToSingle(o.ChildList[i].CondUpper) * 1000);
                                    }
                                    o.ChildList[i].VolInterval = (o.ChildList[i].VolInterval == null) ? null : Convert.ToString(Convert.ToSingle(o.ChildList[i].VolInterval) * 1000);
                                }
                            }
                        }
                        if (o.ProtCondition != null)
                        {
                            o.ProtCondition.VoltageSpan = (o.ProtCondition.VoltageSpan == null) ? "0" : Convert.ToString(Convert.ToSingle(o.ProtCondition.VoltageSpan) * 1000);
                            o.ProtCondition.VoltageMin = (o.ProtCondition.VoltageMin == null) ? "0" : Convert.ToString(Convert.ToSingle(o.ProtCondition.VoltageMin) * 1000);
                            o.ProtCondition.VoltageMax = (o.ProtCondition.VoltageMax == null) ? "0" : Convert.ToString(Convert.ToSingle(o.ProtCondition.VoltageMax) * 1000);
                            o.ProtCondition.Platform1 = (o.ProtCondition.Platform1 == null) ? "0" : Convert.ToString(Convert.ToSingle(o.ProtCondition.Platform1) * 1000);
                            o.ProtCondition.Platform2 = (o.ProtCondition.Platform2 == null) ? "0" : Convert.ToString(Convert.ToSingle(o.ProtCondition.Platform2) * 1000);
                            o.ProtCondition.Platform3 = (o.ProtCondition.Platform3 == null) ? "0" : Convert.ToString(Convert.ToSingle(o.ProtCondition.Platform3) * 1000);
                            o.ProtCondition.VoltageValue = (o.ProtCondition.VoltageValue == null) ? "0" : Convert.ToString(Convert.ToSingle(o.ProtCondition.VoltageValue) * 1000);
                        }
                    }
                    if (dicUnit["Current"] != "A")
                    {
                        o.Current = (o.Current == null) ? null : Convert.ToString(Convert.ToSingle(o.Current) * 1000);
                        o.CutoffCurr = (o.CutoffCurr == null) ? null : Convert.ToString(Convert.ToSingle(o.CutoffCurr) * 1000);
                        o.Amplitude1 = (o.Amplitude1 == null) ? null : Convert.ToString(Convert.ToSingle(o.Amplitude1) * 1000);
                        o.Amplitude2 = (o.Amplitude2 == null) ? null : Convert.ToString(Convert.ToSingle(o.Amplitude2) * 1000);
                        if (o.StepName == "恒流斜坡充电" || o.StepName == "恒流斜坡放电")
                        {
                            o.BeginValue = (o.BeginValue == null) ? null : Convert.ToString(Convert.ToSingle(o.BeginValue) * 1000);
                            o.EndValue = (o.EndValue == null) ? null : Convert.ToString(Convert.ToSingle(o.EndValue) * 1000);
                        }
                        if (o.ChildList != null)
                        {
                            for (int i = 0; i < o.ChildList.Count; i++)
                            {
                                if (o.ChildList[i].ChildStepName == "如果")
                                {
                                    if (o.ChildList[i].JumpCond.Contains("电流"))
                                    {
                                        o.ChildList[i].JumpValue = (o.ChildList[i].JumpValue == null) ? null : Convert.ToString(Convert.ToSingle(o.ChildList[i].JumpValue) * 1000);
                                    }
                                }
                                else if (o.ChildList[i].ChildStepName == "记录条件")
                                {
                                    if (o.ChildList[i].RecordCond == "电流段")
                                    {
                                        o.ChildList[i].CondLower = (o.ChildList[i].CondLower == null) ? null : Convert.ToString(Convert.ToSingle(o.ChildList[i].CondLower) * 1000);
                                        o.ChildList[i].CondUpper = (o.ChildList[i].CondUpper == null) ? null : Convert.ToString(Convert.ToSingle(o.ChildList[i].CondUpper) * 1000);
                                    }
                                    o.ChildList[i].CurrInterval = (o.ChildList[i].CurrInterval == null) ? null : Convert.ToString(Convert.ToSingle(o.ChildList[i].CurrInterval) * 1000);
                                }
                            }
                        }
                        if (o.ProtCondition != null)
                        {
                            o.ProtCondition.CurrentSpan = (o.ProtCondition.CurrentSpan == null) ? null : Convert.ToString(Convert.ToSingle(o.ProtCondition.CurrentSpan) * 1000);
                            o.ProtCondition.CurrentMin = (o.ProtCondition.CurrentMin == null) ? null : Convert.ToString(Convert.ToSingle(o.ProtCondition.CurrentMin) * 1000);
                            o.ProtCondition.CurrentMax = (o.ProtCondition.CurrentMax == null) ? null : Convert.ToString(Convert.ToSingle(o.ProtCondition.CurrentMax) * 1000);
                            o.ProtCondition.CustomerCurrMin = (o.ProtCondition.CustomerCurrMin == null) ? null : Convert.ToString(Convert.ToSingle(o.ProtCondition.CustomerCurrMin) * 1000);
                            o.ProtCondition.CustomerCurrMax = (o.ProtCondition.CustomerCurrMax == null) ? null : Convert.ToString(Convert.ToSingle(o.ProtCondition.CustomerCurrMax) * 1000);
                        }
                    }
                    if (dicUnit["Cap"] != "Ah")
                    {
                        o.Cap = (o.Cap == null) ? null : Convert.ToString(Convert.ToSingle(o.Cap) * 1000);
                        if (o.ChildList != null)
                        {
                            for (int i = 0; i < o.ChildList.Count; i++)
                            {
                                if (o.ChildList[i].ChildStepName == "如果")
                                {
                                    if (o.ChildList[i].JumpCond.Contains("容量"))
                                    {
                                        o.ChildList[i].JumpValue = (o.ChildList[i].JumpValue == null) ? null : Convert.ToString(Convert.ToSingle(o.ChildList[i].JumpValue) * 1000);
                                    }
                                }
                            }
                        }
                    }
                    if (dicUnit["Energy"] != "Wh")
                    {
                        o.Energy = (o.Energy == null) ? null : Convert.ToString(Convert.ToSingle(o.Energy) * 1000);
                        if (o.ChildList != null)
                        {
                            for (int i = 0; i < o.ChildList.Count; i++)
                            {
                                if (o.ChildList[i].ChildStepName == "如果")
                                {
                                    if (o.ChildList[i].JumpCond.Contains("能量"))
                                    {
                                        o.ChildList[i].JumpValue = (o.ChildList[i].JumpValue == null) ? null : Convert.ToString(Convert.ToSingle(o.ChildList[i].JumpValue) * 1000);
                                    }
                                }
                            }
                        }
                    }
                    if (dicUnit["Power"] != "W")
                    {
                        o.Power = (o.Power == null) ? null : Convert.ToString(Convert.ToSingle(o.Power) * 1000);
                        if (o.ChildList != null)
                        {
                            for (int i = 0; i < o.ChildList.Count; i++)
                            {
                                if (o.ChildList[i].ChildStepName == "如果")
                                {
                                    if (o.ChildList[i].JumpCond.Contains("功率"))
                                    {
                                        o.ChildList[i].JumpValue = (o.ChildList[i].JumpValue == null) ? null : Convert.ToString(Convert.ToSingle(o.ChildList[i].JumpValue) * 1000);
                                    }
                                }
                            }
                        }
                    }
                    if (dicUnit["Res"] != "Ω")
                    {
                        o.LoadResistor = (o.LoadResistor == null) ? null : Convert.ToString(Convert.ToSingle(o.LoadResistor) * 1000);
                    }
                    if (dicUnit["Temp"] != "℃")
                    {
                        o.MaxTi = (o.MaxTi == null) ? null : Convert.ToString(Convert.ToSingle(o.MaxTi) * 33.8);
                        o.MinTi = (o.MinTi == null) ? null : Convert.ToString(Convert.ToSingle(o.MinTi) * 33.8);
                        if (o.ProtCondition != null)
                        {
                            o.ProtCondition.TemperatureMax = (o.ProtCondition.TemperatureMax == null) ? "0" : Convert.ToString(Convert.ToSingle(o.ProtCondition.TemperatureMax) * 33.8);
                        }
                    }
                }
            });
            return stepInfoList;
        }
        /// <summary>
        /// 将工步保护条件数值转换成默认单位对应数值
        /// </summary>
        /// <param name="protCon"></param>
        /// <returns></returns>
        public static ProtectCondition GetDefaultProtect(ProtectCondition protCon)
        {
            //读取当前单位定制的单位
            Dictionary<string, string> dicUnit = IniControl.ReadCustom("unit custom");
            if (dicUnit["Time"] != "sec")
            {
                protCon.TimeSpan = Convert.ToString(Convert.ToSingle(protCon.TimeSpan) / 1000);
                protCon.StepDelay = Convert.ToString(Convert.ToSingle(protCon.StepDelay) / 1000);
                protCon.ContinueDelay = Convert.ToString(Convert.ToSingle(protCon.ContinueDelay) / 1000);
                protCon.DetectionTime = Convert.ToString(Convert.ToSingle(protCon.DetectionTime) / 1000);
            }
            if (dicUnit["Voltage"] != "V")
            {
                protCon.VoltageSpan = Convert.ToString(Convert.ToSingle(protCon.VoltageSpan) / 1000);
                protCon.VoltageMin = Convert.ToString(Convert.ToSingle(protCon.VoltageMin) / 1000);
                protCon.VoltageMax = Convert.ToString(Convert.ToSingle(protCon.VoltageMax) / 1000);
                protCon.Platform1 = Convert.ToString(Convert.ToSingle(protCon.Platform1) / 1000);
                protCon.Platform2 = Convert.ToString(Convert.ToSingle(protCon.Platform2) / 1000);
                protCon.Platform3 = Convert.ToString(Convert.ToSingle(protCon.Platform3) / 1000);
                protCon.VoltageValue = Convert.ToString(Convert.ToSingle(protCon.VoltageValue) / 1000);
            }
            if (dicUnit["Current"] != "A")
            {
                protCon.CurrentSpan = Convert.ToString(Convert.ToSingle(protCon.CurrentSpan) / 1000);
                protCon.CurrentMin = Convert.ToString(Convert.ToSingle(protCon.CurrentMin) / 1000);
                protCon.CurrentMax = Convert.ToString(Convert.ToSingle(protCon.CurrentMax) / 1000);
                protCon.CustomerCurrMin = Convert.ToString(Convert.ToSingle(protCon.CustomerCurrMin) / 1000);
                protCon.CustomerCurrMax = Convert.ToString(Convert.ToSingle(protCon.CustomerCurrMax) / 1000);
            }
            if (dicUnit["Temp"] != "℃")
            {
                protCon.TemperatureMax = Convert.ToString(Convert.ToSingle(protCon.TemperatureMax) / 1000);
            }
            return protCon;
        }
        /// <summary>
        /// 将默认单位保护条件数值转换成当前单位对应的数值
        /// </summary>
        /// <param name="data"></param>
        /// <param name="defaultUnit"></param>
        /// <param name="currentUnit"></param>
        /// <returns></returns>
        public static ProtectCondition GetCurrentProtect(ProtectCondition protCon)
        {
            //读取当前单位定制的单位
            Dictionary<string, string> dicUnit = IniControl.ReadCustom("unit custom");
            if (dicUnit["Time"] != "sec")
            {
                protCon.TimeSpan = Convert.ToString(Convert.ToSingle(protCon.TimeSpan) * 1000);
                protCon.StepDelay = Convert.ToString(Convert.ToSingle(protCon.StepDelay) * 1000);
                protCon.ContinueDelay = Convert.ToString(Convert.ToSingle(protCon.ContinueDelay) * 1000);
                protCon.DetectionTime = Convert.ToString(Convert.ToSingle(protCon.DetectionTime) * 1000);
            }
            if (dicUnit["Voltage"] != "V")
            {
                protCon.VoltageSpan = Convert.ToString(Convert.ToSingle(protCon.VoltageSpan) * 1000);
                protCon.VoltageMin = Convert.ToString(Convert.ToSingle(protCon.VoltageMin) * 1000);
                protCon.VoltageMax = Convert.ToString(Convert.ToSingle(protCon.VoltageMax) * 1000);
                protCon.Platform1 = Convert.ToString(Convert.ToSingle(protCon.Platform1) * 1000);
                protCon.Platform2 = Convert.ToString(Convert.ToSingle(protCon.Platform2) * 1000);
                protCon.Platform3 = Convert.ToString(Convert.ToSingle(protCon.Platform3) * 1000);
                protCon.VoltageValue = Convert.ToString(Convert.ToSingle(protCon.VoltageValue) * 1000);
            }
            if (dicUnit["Current"] != "A")
            {
                protCon.CurrentSpan = Convert.ToString(Convert.ToSingle(protCon.CurrentSpan) * 1000);
                protCon.CurrentMin = Convert.ToString(Convert.ToSingle(protCon.CurrentMin) * 1000);
                protCon.CurrentMax = Convert.ToString(Convert.ToSingle(protCon.CurrentMax) * 1000);
                protCon.CustomerCurrMin = Convert.ToString(Convert.ToSingle(protCon.CustomerCurrMin) * 1000);
                protCon.CustomerCurrMax = Convert.ToString(Convert.ToSingle(protCon.CustomerCurrMax) * 1000);
            }
            if (dicUnit["Temp"] != "℃")
            {
                protCon.TemperatureMax = Convert.ToString(Convert.ToSingle(protCon.TemperatureMax) * 1000);
            }
            return protCon;
        }
        /// <summary>
        /// 把单元格或保护条件中文本框的值转为默认单位数值
        /// </summary>
        /// <param name="value"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static float GetDefaultData(string value,string type)
        {
            //获得数值
            float customValue = Convert.ToSingle(value);
            //读取当前单位定制的单位
            Dictionary<string, string> dicUnit = IniControl.ReadCustom("unit custom");
            switch(type)
            {
                case "Volt":
                    {
                        if (dicUnit["Voltage"] != "V")
                        {
                            customValue = customValue / 1000;
                        }
                    }break;
                case "Curr":
                    {
                        if (dicUnit["Current"] != "A")
                        {
                            customValue = customValue / 1000;
                        }
                    }break;
            }
            return customValue;
        }
    }
}
